package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.po.PageRequest;
import com.example.demo.po.PageResult;
import com.example.demo.po.TBizArt;
import com.example.demo.po.TBizOrder;
import com.example.demo.service.TBizOrderService;
import com.example.demo.util.CodeCache;
import com.example.demo.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ajax/intercept")
public class intercept {
    @Autowired
    TBizOrderService tBizOrderService;

    @RequestMapping(value = "/orderCreat",method = RequestMethod.POST)
    public String orderCreat(@RequestParam Map<String,String> map, HttpServletRequest request, HttpSession session){
        JSONObject jsonObject = new JSONObject();
        try{
            String userid =map.get("userid");
            String artCodes =map.get("artCodes");
            String price = map.get("price");
            System.out.println(artCodes);
            TBizOrder orderInfo = new TBizOrder();
            orderInfo.setUserid(userid);
            orderInfo.setOrderstate("1");
            orderInfo.setPrice(price);
            String cdate = DateUtil.formatDate(new Date());
            orderInfo.setCreatetime(cdate);
            System.out.println(orderInfo.getCreatetime());
            orderInfo.setIntegral("0");
            if(tBizOrderService.saveInfo(orderInfo,artCodes)){
                jsonObject.put("oper_res",true);
            }else{
                jsonObject.put("oper_res",false);
            }
        }catch (Exception e){
            e.printStackTrace();
            jsonObject.put("oper_res",false);
        }
        return  jsonObject.toJSONString();
    }

//    @RequestMapping(value = "/orderList")
//    public String orderList(@RequestParam("userid") String userid,
//                            @RequestParam("pageNum") Integer pageNum,
//                            @RequestParam("type") Integer type,
//                            @RequestParam("pageSize") Integer pageSize,
//                            HttpServletRequest request, HttpSession session){
//        JSONObject jsonObject = new JSONObject();
//        try{
//            PageRequest page = new PageRequest();
//            page.setPageNum(pageNum);
//            page.setPageSize(pageSize);
//            TBizOrder order =new TBizOrder()l
//            PageResult result = tBizOrderService.findByPage(userid,page);
//            jsonObject.put("oper_res",true);
//            jsonObject.put("data",result);
//        }catch (Exception e){
//            e.printStackTrace();
//            jsonObject.put("oper_res",false);
//            jsonObject.put("data","请求失败");
//        }
//        return jsonObject.toJSONString();
//    }



}
